﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.admin
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
             if(!Page.IsPostBack)
            {
                join();
            }
        }

        public void join()
        {
            var app = this.dc.PolicyApprovalDetails.Join(dc.policies, a => a.policyid, p => p.policyid, (a, p) => new
            {
                a.idapproval,
                a.policyid,
                a.requestid,
                a.date,
                a.amount,
                p.policyname
            }).Join(dc.PolicyRequestDetails, a => a.requestid, r => r.requestid, (a, r) => new
            {
                a.idapproval,
                a.policyid,
                a.requestid,
                a.date,
                a.amount,
                a.policyname,
                r.empno
            }).Join(dc.EmpRegisters, a => a.empno, l => l.empno, (a, l) => new
            {
                a.idapproval,
                a.policyid,
                a.requestid,
                a.date,
                a.amount,
                a.policyname,
                a.empno,
                l.username
            }).OrderByDescending(c => c.idapproval);
            this.Repeater1.DataSource = app.ToList();
            this.Repeater1.DataBind();
        }
        protected void LinkButtonXoa_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lb = (LinkButton)sender;
                HiddenField hd = (HiddenField)lb.Parent.FindControl("HiddenFieldApp");

                PolicyApprovalDetail pol = this.dc.PolicyApprovalDetails.Single(a => a.idapproval == Convert.ToInt32(hd.Value));

                this.dc.PolicyApprovalDetails.DeleteOnSubmit(pol);
                this.dc.SubmitChanges();
                join();
                this.mesage_success.Visible = true;

            }
            catch
            {
                this.mesage_success.Visible = false;
            }
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            this.mesage_success.Visible = false;
        }
    }
}